<template>
	<view>
		<view class="detail-box">
			<view class="cu-form-group">
				<view class="title">商品名称：<span class="padd_left">{{NowSelectGoods.GoodsName}}</span></view>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<!-- <span class="padd_left"></span> -->
			<view class="cu-form-group">
				<view class="title">编　　号：<span class="padd_left">{{NowSelectGoods.GoodsCode}}</span></view>
			</view>
			<view class="cu-form-group">
				<view class="title">规　　格：<span class="padd_left">{{NowSelectGoods.Spec}}</span></view>
				<!-- <input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.Spec"></input> -->
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			</view>
			<view class="cu-form-group" @tap="clickopen(2,'仓库')">
				<view class="title">仓　　库：<span class="padd_left">{{NowSelectGoods.stockName}}</span></view>
			</view>
			<view class="cu-form-group" v-if="Isdistribution == 1" @tap="clickopen(5,'配入仓库')">
				<view class="title">配入仓库：<span class="padd_left">{{NowSelectGoods.stockName2}}</span></view>
			</view>
			<view class="cu-form-group" @tap="clickopen(4,'单位')">
				<view class="title">单　　位：</view>
				<input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.UnitName"></input>
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			</view>
			<view class="cu-form-group" @tap="clickopen(3,'赠品')">
				<view class="title">赠　　品：<span class="padd_left">{{NowSelectGoods.Giftname}}</span></view>
			</view>
			<view class="cu-form-group">
				<view class="title">批　　号：

					<!-- 	<span v-if="IsBatch==true" class="padd_left">{{NowSelectGoods.BatchNo}}</span>
			
			<span v-else class="padd_left" style="color: rgba(0, 0, 0, 0.6);">不是批号商品</span> -->
					<!-- <input v-else disabled="true"  placeholder="不是批号商品"></input> -->
				</view>
				<input :disabled="!IsBatch" v-model="NowSelectGoods.BatchNo" @input="GetBatchNo" :placeholder="IsBatch==true?'请输入批号或者选择批号':'不是批号商品'"></input>
				<!-- <input class="inpt" name="input"></input> -->
				<button class="cu-btn  stop text-white" style="background-color: #518abc;" v-if="IsBatch==true" @tap.stop="XHGetBatchNoFollow()">查询</button>
			</view>
			<view class="cu-form-group" @tap="changeShow('QS_Picekr_date',0)">
				<view class="title">生产日期：</view>
				<input disabled="true" v-model="ProductionDate" :placeholder="datePlaceHolder"></input>
			</view>
			<view class="cu-form-group" @tap="changeShow('QS_Picekr_date',1)">
				<view class="title">有效日期：</view>
				<input disabled="true" :value="validityDate" :placeholder="datePlaceHolder"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">税　　率：</view>
				<input class="inpt" type="number" name="input" @input="oninputs" placeholder="点击修改" v-model="NowSelectGoods.Tax"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">单　　价：</view>
				<input type="number"  v-model="NowSelectGoods.Price" placeholder="请输入单价">
				<view class="btn_price" @tap="clickopen(1,'单价')">选择</view>
				<!-- <button class="cu-btn round stop text-white">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">折　　扣：</view>
				<input class="inpt" type="number" name="input" placeholder="点击修改" v-model="NowSelectGoods.Discount"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">数　　量：</view>
				<input class="inpt" type="number" name="input" placeholder="点击修改" v-model="NowSelectGoods.Qty"></input>
			</view>

			<view class="cu-form-group">
				<view class="title">库　　存：</view>
				<input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.stockqty"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">备　　注：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Remark"></input>
			</view>
			<view class="cu-form-group">
				<!-- <button class="cu-btn  stop text-white" @tap="AddBillOrder">提交修改</button> -->
				<input class="inpt" name="input" disabled="true"></input>
				<button style="background-color: #518abc;" class="cu-btn  stop text-white" @tap="addSelectGoods">提交修改</button>
			</view>
		</view>
		<view class="cu-modal" :class="isShowScanModel?'show':''">
			<view class="cu-dialog ls-main">
				<view class="cu-bar bg-ls justify-between">
					<view class="action">
						<view class="cuIcon-info text-white" v-show="false"></view>
					</view>
					<view class="content text-white" style="color: #000;">选择批号</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-white" style="color: #000;font-size: 18px;"></text>
					</view>
				</view>
				<view class="padding text-left bg-white ls-contain" style="height: 100%;">
					<scroll-view scroll-y style="height: calc(100% - 1px);padding-bottom: 30px">
						<!-- <view class="ls-box" @tap="choosesGoods(index)" v-for="(item,index) in storeList" :key='index' :data-index="index">
						
							<view>批次号:{{item.Inventorybatch}}</view>
						</view> -->
						<view class="ls-box" @tap="choosesGoods(index)" v-for="(item,index) in storeList" :key='index' :data-index="index">
							<!-- <view class="text-black">数据库：</view> -->
							<view>批次号:{{item.FBatchNo}}</view>
						</view>
					</scroll-view>
				</view>
			</view> 
		</view>
		<!-- <uni-calendar ref="calendar1" :insert="false" @confirm="confirm1" />
		<uni-calendar ref="calendar2" :insert="false" @confirm="confirm2" /> -->
		<!-- 弹出框HOME -->
		<view class="cu-modal cu_none " :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog" :class="[{'new-cu-dialog':listshow == 3}]">
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择{{listcode}}</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view style="padding: 5px 21px;">
					<view class="search" v-show="listshow == 11"><input class="inpt" placeholder="查询供应商" name="input"></input>
						<span class="search_span" @tap="selectClient()">搜索</span>
					</view>
					<view class="search" v-show="listshow == 2"><input class="inpt" placeholder="查询仓库" name="input"></input>
						<span class="search_span" @tap="selectwarehouse()">搜索</span>
					</view>
					<view class="search" v-show="listshow == 44"><input class="inpt" placeholder="查询业务员" name="input"></input>
						<span class="search_span" @tap="selectsalesmant()">搜索</span>
					</view>
				</view>
				<scroll-view style="height: 77%;" scroll-y="true">
					<view class="padding-xl" v-show="listshow == 1">
						<view>
							<view class="btn_list" v-for="(item,index) in Pricelist" @tap="clickPrice(index)" :key="item.id">
								<span>{{item.PriceType+':'}}</span>
								<span style="padding-left: 12px;">{{item.Price}}</span>
								<!-- {{item.PriceType+item.Price}}-->
							</view>
						</view>
					</view>
					<view class="padding-xl" v-show="listshow == 2">
						<view>
							<view class="btn_list" v-for="(item,index) in StoreLists" @tap="checkware(index)" :key="item.id">{{item.StoreName}}</view>
						</view>
					</view>
					<view class="padding-xl" v-show="listshow == 3">
						<view>
							<view class="btn_list" v-for="(item,index) in Gift" @tap="clickGift(index)" :key="item.id">{{item.Gname}}</view>
						</view>
					</view>
					<view class="padding-xl" v-show="listshow == 4">
						<view class="btn_list" v-for="(item,index) in GoodsUnit" @tap="clickUnit(index)" :key="item.id">{{item.UnitName}}</view>
					</view>
					<view class="padding-xl" v-show="listshow == 5">
						<view>
							<view class="btn_list" v-for="(item,index) in StoreLists2" @tap="checkware2(index)" :key="item.id">{{item.StoreName}}</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 弹出框END -->
		<QSpicker title="请选择日期时间" mode="bottom" type="date" ref="QS_Picekr_date" pickerId="date_1" :dataSet="dateSet"
		 showReset :autoHide="false" contentColor="#33cc33" :lineHeight=".05" @hideQSPicker="hideQSPicker($event)"
		 @showQSPicker="showQSPicker($event)" @confirm="newconfirm($event)" />
	</view>
</template>
<script>
	import * as Api from '@/syApis/syAddOrder/syaddApis.js';
	// import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
	import QSpicker from '@/components/QuShe-picker/QuShe-picker.vue';
	import * as CommonFun from "@/common/common.js";
	import * as GetApi from '@/syApis/syHttp/Http.js';
	export default {
		data() {
			return {
				//选择的商品
				NowSelectGoods: {
					ProductionDate: ''
				},
				ProductionDate: '',
				validityDate: '',
				//仓库ID
				StoreID: "",
				//当前商品在原商品数组对应的位置
				SelectStockNum: "",
				storeList: [],
				Tax: '',
				StoreLists: [],
				StoreLists2: [],
				orderType: 2,
				Inventorybatch: "",
				isShowScanModel: false,
				//日期palceholde
				datePlaceHolder: "点击选择日期",
				Gift: [{
					Gname: '否'
				}, {
					Gname: '是'
				}], //是否赠品
				listshow: -1,
				modalName: null,
				Pricelist: [], //单价
				listcode: '',
				IsBatch: false, //批号商品
				GoodsUnit: [], //多单位
				ClientID: '',
				Isdistribution: null, //是否配入仓库
				//日期选择
				dateSet: {
					dateMode: 3,
					dateFormatArray: ['-', '-', ' ', ':', ':']
				},
			}
		},
		created() {
			this.GetStoreMessage();
		},
		onLoad(options) {
			console.log(options);
			console.log(options.goodData)
			this.NowSelectGoods = JSON.parse(options.goodData);
			// this.source = JSON.parse(options.source);
			this.source = JSON.parse(uni.getStorageSync("source",""));
			console.log(this.NowSelectGoods)
			// this.BillName = options.name
			this.BillName = options.name
			this.Inventorybatch = options.Inventorybatch;
			this.Isdistribution = options.Isdistribution;
			this.NowSelectGoods.Tax = 0; //税率赋默认值0
			this.NowSelectGoods.Discount = 100; //折扣赋默认值100
			this.NowSelectGoods.Giftname = '否'; //赠品 赋默认值否
			this.NowSelectGoods.IsGift = this.NowSelectGoods.IsGift == "" || this.NowSelectGoods.IsGift == undefined || 
			this.NowSelectGoods.IsGift == "0"?"0":"1"; //赠品 赋默认值否
			this.IsBatch = this.NowSelectGoods.IsBatch; //是否是批号商品
			this.ClientID = options.ClientID;
			this.StoreID2 = options.StoreID2;
			this.batch = options.batch;
			this.isquote = options.isquote;
			this.Order = JSON.parse(uni.getStorageSync("Order",""));
			// this.Order = JSON.parse(options.Order);
			this.prices(); //获取单价
			this.getGoodsUnitMessage(); //获取多单位
			if (this.IsBatch == false) {
				this.datePlaceHolder = '不可选择日期'
			}
			this.XHGetBatchNoFollow(1)
			console.log(this.NowSelectGoods)
			this.Assignment(this.NowSelectGoods)
			// this.SelectStockNum(this.NowSelectGoods.GoodsID);
		},
		components: {
			QSpicker
		},
		// watch:{
		// 	// 数量不能超过10000
		// 	NowSelectGoods:{
		// 		handler:function(values) {
		// 			console.log(values)
		// 		},
		// 		deep:true
		// 	},
		// },
		methods: {
			//如果是源单商品，赋值源单商品税率，折扣，单价，
			Assignment(data){
				var batchs = false;
				var delivery = false;
				if(this.batch == 1){
					batchs = true
				}
				if(this.Isdistribution == 1){
					delivery = true
				}
				console.log('选中的商品')
				console.log(data)
				
				// var data = this.NowSelectGoods
				var source =  this.source 
				console.log('源单商品')
				console.log(source)
				for(var i in source){
					console.log('如果是源单商品==========是否相等---------------')
					console.log(this.isidentical(source[i],data,delivery))
					//如果等于true   存在的商品与添加的商品数量想加  用于判断是否大于源单数量
					if(this.isidentical(source[i],data,delivery) == true){
							data["Discount"] = source[i]["Discount"]
							data["Tax"] = source[i]["Tax"]
							data["Price"] = source[i]["Price"]
							data["IsGift"] = source[i]["IsGift"]
							break
					}
				}
				data.Qty = ''
				if(data.IsGift == "" || data.IsGift == undefined || data.IsGift == "0"){
					this.NowSelectGoods.Giftname = '否'
				}else{
					this.NowSelectGoods.Giftname = '是'
				}
				this.NowSelectGoods  = data 
			},
			isidentical:function(Good,Sood,delivery){
				var status = false
				console.log('源单商品合并==================================')
				// console.log(Good["BarCode"] == Sood["BarCode"],'条码','源单'+Good["BarCode"],'选中的商品'+Sood["BarCode"])
				console.log(Good["GoodsID"] == Sood["GoodsID"],'商品','源单'+Good["GoodsID"],'选中的商品'+Sood["GoodsID"])
				console.log(Good["StoreID"] == Sood["StoreID"],'仓库','源单'+Good["StoreID"],'选中的商品'+Sood["StoreID"])
				console.log(Good["UnitID"] == Sood["UnitID"],'单位','源单'+Good["UnitID"],'选中的商品'+Sood["UnitID"])
				// console.log(Good["IsGift"] == Sood["IsGift"],'赠品','源单'+Good["IsGift"],'选中的商品'+Sood["IsGift"])
				if(
				// Good["BarCode"] == Sood["BarCode"]
				Good["GoodsID"] == Sood["GoodsID"]
				&& Good["StoreID"] == Sood["StoreID"]
				&& Good["UnitID"] == Sood["UnitID"]
				&& Good["IsGift"] == Sood["IsGift"]
				){
					if(delivery){
						if(Good["StoreID2"] == Sood["StoreID2"]){
						status = true	
						}
					}else{
						status = true
					}
				}
				return status
			},
			//获取批号
			XHGetBatchNoFollow(e) {
				let data = {
					StoreID: this.NowSelectGoods.StoreID,
					GoodsID: this.NowSelectGoods.GoodsID,
					BillName: this.BillName,
				};
				var that = this;
				Api.XHGetBatchNoFollow(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {
							console.log('获取登陆信息失败!')
						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.data.ErrorMsg);
						} else {
							that.storeList = res.data.ResultMsg;
							if (res.data.ResultMsg.length > 0) {
								if (e != 1) {
									that.isShowScanModel = true;
								}
							} else {
								if (e != 1) {
									Api.showTip('查无批号');
								}
								
							}
						}
					}
				})
			},
			oninputs(e) {
				var that = this
				var str = e.detail.value; //这是一字符串
				var strarr = new Array(); //定义一数组
				strarr = str.split(""); //字符分割
				var rep = /[\.]/; //定义小数点正则表达式
				var pattern = new RegExp("[0-9]+"); //定义数字正则表达式
				var returnstr = ''
				console.log(strarr)
				for (var i in strarr) {
					if (pattern.test(strarr[i]) || rep.test(strarr[i])) {
						console.log('正确')
						returnstr += strarr[i]
					} else {
						console.log('错误')
					}
				}
				console.log('正确的字符串')
				console.log(returnstr)
				that.Tax = returnstr
				console.log(that.NowSelectGoods.Tax)
				// cobsole.__lookupGetter__()
				console.log('这是一个打印的')
				// this.GetStoreMessage()
				// return
			},
			choosesGoods(index) {
				// console.log(this.storeList[index])
				// return
				// this.validityDate.fulldate = this.storeList[index].FDate;
				// this.validityDate.fulldate = this.storeList[index].FValidDate;
				// this.NowSelectGoods.FDate = this.storeList[index].FDate;
				// this.NowSelectGoods.FValidDate =  this.storeList[index].FValidDate;
				this.ProductionDate = this.timesubstr(this.storeList[index].FDate);
				this.validityDate = this.timesubstr(this.storeList[index].FValidDate);
				this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
				this.NowSelectGoods.validityDate = this.storeList[index].FValidDate;
				this.NowSelectGoods.BatchNo = this.storeList[index].FBatchNo;
				this.NowSelectGoods.stockqty = parseFloat(this.storeList[index].FQty);
				this.isShowScanModel = false;
			},
			// 日期截取
			timesubstr: function(e) {
				return e == '' || e == undefined ? '' : e.substring(0, 10)
			},
			//选中的赠品
			clickGift(evt) {
				this.NowSelectGoods.IsGift = this.Gift[evt].Gname
				this.NowSelectGoods.Giftname = this.Gift[evt].Gname
				this.modalName = null;
				console.log(evt)
			},
			// 选择单价
			clickPrice: function(evt) {
				this.NowSelectGoods.Price = parseFloat(this.Pricelist[evt]["Price"])
				this.modalName = null;
			},
			//选中的单位
			clickUnit: function(index) {
				this.NowSelectGoods.UnitName = this.GoodsUnit[index]["UnitName"];
				this.NowSelectGoods.UnitID = this.GoodsUnit[index]["UnitID"];
				this.NowSelectGoods.urate = this.GoodsUnit[index]["urate"];
				this.modalName = null;
				this.prices()
			},
			//显示
			clickopen: function(evt, msg) {
				this.listshow = Number(evt);
				this.listcode = msg;
				this.modalName = 'Modal';
			},
			//关闭
			hideModal() {
				this.modalName = null;
				this.isShowScanModel = null
			},
			checkware: function(e) {
				this.NowSelectGoods["StoreID"] = this.StoreLists[e]["StoreID"]
				this.NowSelectGoods["stockName"] = this.StoreLists[e]["StoreName"]
				this.modalName = null
			},
			checkware2: function(e) {
				this.NowSelectGoods["StoreID2"] = this.StoreLists[e]["StoreID"]
				this.NowSelectGoods["stockName2"] = this.StoreLists[e]["StoreName"]
				this.modalName = null
				console.log('选中的仓库')
				console.log(this.NowSelectGoods)
			},
			//显示选择日期界面
			changeShow(name, type) {
				this.startAndEndTime = type;
				this.$refs[name].show();
				this.dateName = name;
			},
			showQSPicker(res) {
				console.log(res);
			},
			hideQSPicker(res) {
			 
			},
			newconfirm(res) {
				// if (this.startAndEndTime == 0) {
				// 	this.startTime = res.data;
				// } else {
				// 	this.endTime = res.data;
				// }
				console.log(res)
				if(this.IsBatch==true){
					var data = this.splitdate(res.data);//处理的日期
					if(this.startAndEndTime == 0){
						
						this.ProductionDate = data;          
						this.NowSelectGoods.ProductionDate = data;
						this.validityDate = this.DateToTime(data,0,this.NowSelectGoods.Days);
						this.NowSelectGoods.validityDate = this.DateToTime(data,0,this.NowSelectGoods.Days);
						
					}else if(this.startAndEndTime == 1){
						this.validityDate = data,
						this.NowSelectGoods.validityDate = data;
						this.ProductionDate = this.DateToTime(data,1,this.NowSelectGoods.Days);
						this.NowSelectGoods.ProductionDate = this.DateToTime(data,1,this.NowSelectGoods.Days);
					}
					this.$refs[this.dateName].hide();
				}
				
				// console.log('点击了确认')
				// console.log(res)
				// console.log(this.startAndEndTime)
				
				// console.log("处理的日期")
				// console.log(data)
				// // var fulldata = res.data
				// // this.checkdata.BillTime = data
				// console.log(res)
				
			},
			open1() {
				if (this.IsBatch == true) {
					this.$refs.calendar1.open();
				}
			},
			open2() {
				if (this.IsBatch == true) {
					this.$refs.calendar2.open();
				}
			},
			confirm1(e) {
				var splitdata = this.splitdate(e.fulldate)
				this.ProductionDate = splitdata;
				this.NowSelectGoods.ProductionDate = splitdata;

			},
			confirm2(e) {
				var splitdata = this.splitdate(e.fulldate)
				this.validityDate = splitdata,
					this.NowSelectGoods.validityDate = splitdata;
			},
			//处理日期
			splitdate(evt) {
				if (evt == "" || evt == undefined) {
					return
				}
				var str = evt; //这是一字符串
				var strarr = new Array(); //定义一数组
				strarr = str.split("-"); //以---号分割成数组
				//循环数组判断 月和日是否是个位数 如果是则在前面添加一个0
				for (var i = 1; i < strarr.length; i++) {
					console.log(strarr[i].length);
					if (strarr[i].length < 2) {
						strarr[i] = ("0" + strarr[i]);
					}
				}
				var newstr = strarr.join("-"); //链接字符串
				return newstr;
			},
			//获取仓库
			GetStoreMessage() {
				let data = {
					Filter: ""
				}
				var that = this;
				Api.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							that.StoreLists = res.data.ResultMsg;
							that.StoreLists2 = res.data.ResultMsg;
						}
					} else {
						Api.showTip("登录超时");
					}
				});
			},
			indexOfs:function(e){
				var str = "'"+e+"'"
				console.log('是否包含小数')
				console.log(str)
				console.log(str.indexOf(".") != -1)
				return str.indexOf(".") != -1
			},
			//获取当前选择的商品
			addSelectGoods() {
				// if (this.index2 == -1 && this.orderType != 10) {
				// 	Api.showTip("请选选择仓库");
				// 	return;
				// }
				if (this.IsBatch == true) {
					if (this.NowSelectGoods.BatchNo == "" || this.NowSelectGoods.BatchNo == undefined) {
						Api.showTip("请选择批号!");
						return;
					}
				}
				if(this.indexOfs(this.NowSelectGoods.Tax)){
					uni.showToast({
						title:'税率不能包含小数!',
						icon:'none'
					})
					return
				}
				if(this.indexOfs(this.NowSelectGoods.Discount)){
					uni.showToast({
						title:'折扣不能包含小数!',
						icon:'none'
					})
					return
				}
				if (this.NowSelectGoods.Qty == 0 || this.NowSelectGoods.Qty == undefined) {
					// Api.showTip("商品数量不能少于一件!");
					uni.showToast({
						title: '商品数量不能少于一件!',
						icon: 'none'
					})
					return
				}
				
				
				this.NowSelectGoods.GoodsStorm = this.GoodsStorm;
				//如果数量为空则赋值1
				if (this.NowSelectGoods.Qty == '' || this.NowSelectGoods.Qty == undefined) {
					this.NowSelectGoods.Qty = 1
				}
				if (this.NowSelectGoods.IsGift == '是') {
					this.NowSelectGoods.IsGift = 1
				} else {
					this.NowSelectGoods.IsGift = 0
				}

				console.log('返回的参数')
				console.log(this.NowSelectGoods);
				// return
				this.computPrice()
				var result = this.Isbill(this.NowSelectGoods)
				var that = this
				if (result.Isbills == 0) {
					Api.showConfirm("源单明细中没有此商品,是否添加？", function(state) {
						if (state) {
							that.$eventHub.$emit('fireredact', JSON.stringify(that.NowSelectGoods));
							uni.navigateBack({
								delta: 1
							})
						}
					})
				} else if (result.Isgreater == 1) {
					Api.showConfirm("录入的数量大于源单数量,是否添加？", function(state, ) {
						if (state) {
							that.$eventHub.$emit('fireredact', JSON.stringify(that.NowSelectGoods));
							uni.navigateBack({
								delta: 1
							})
						}
					})
				} else {
					that.$eventHub.$emit('fireredact', JSON.stringify(that.NowSelectGoods));
					uni.navigateBack({
						delta: 1
					})
				}
				console.log('返回的参数')
				console.log(this.NowSelectGoods)
				// return
				// this.$eventHub.$emit('fireredact', JSON.stringify(this.NowSelectGoods));
				// uni.navigateBack({
				// 	delta:1
				// })
			},
			//判断是否在单据里面  判断商品数量是否大于单据数量
			//判断录入数量是否大于源单数量
			Isbill: function(data) {
				var result = {
					Isbills: 0,
					Isgreater: 0,
				}
				var that = this;
				var batchs = false;
				var delivery = false;
				if(that.batch == 1){
					batchs = true
				}
				if(that.Isdistribution == 1){
					delivery = true
				}
				for(var i in this.Order){
					console.log('是否相等-----------------------------')
					console.log(CommonFun.isequality(this.Order[i],data,batchs,delivery))
					//如果等于true   存在的商品与添加的商品数量想加  用于判断是否大于源单数量
					if(CommonFun.isequality(this.Order[i],data,batchs,delivery) == true){
							data["nnnqty"] = parseFloat(data["Qty"])+parseFloat(this.Order[i]["Qty"])
					}
				}
				console.log('相加后的数量')
				console.log(data["nnnqty"])
				var tmpGoods = this.source
				console.log('数组对比');
				console.log(data);
				console.log(tmpGoods)
				for (var j in tmpGoods) {
					tmpGoods[j]["IsGift"] = tmpGoods[j]["IsGift"] == false || tmpGoods[j]["IsGift"] == "0" ? "0" : "1";
					tmpGoods[j]["Qty"] = parseFloat(tmpGoods[j]["Qty"])
						console.log('是源单商品')
						console.log('输入的数量')
						console.log(parseFloat(data["Qty"]))
						console.log('源单的数量')
						// for()
						if(CommonFun.isequality(tmpGoods[j],data,batchs,delivery) == true){
							
						
						if (that.batch == 1) {
							console.log('----------------是-----是---是-----------------')
							result.Isbills = 1;
							if ((parseFloat(data["nnnqty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))) {
								result.Isgreater = 1;
							}else{
								if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
									result.Isgreater = 1;
								}
							}
						} else {
							console.log('----------------不是是---------不是是-----------')
							console.log(tmpGoods[j]["Qty"])
							if (that.isnulls(tmpGoods[j]["BatchNo"]) == that.isnulls(data["BatchNo"])
							 && that.isnulls(that.timesubstr(tmpGoods[j]["ProductionDate"])) == that.isnulls(that.timesubstr(data["ProductionDate"])) 
							 && that.isnulls(that.timesubstr(tmpGoods[j]["validityDate"])) == that.isnulls(that.timesubstr(data["validityDate"]))
							) {
								if(delivery){
									if(tmpGoods[j]["StoreID2"] == data["StoreID2"]){
										result.Isbills = 1;
										 if(that.isquote == 1){
											if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["UNQTY"])) {
												result.Isgreater = 1;
											}else{
												if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
													result.Isgreater = 1;
												}
											}
										}else if(that.isquote == 2){
											if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["Qty"])) {
												result.Isgreater = 1;
											}else{
												if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["Qty"]))){
													result.Isgreater = 1;
												}
											}
										}
									}
								}else{
								 result.Isbills = 1;
								 if(that.isquote == 1){
									if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["UNQTY"])) {
										result.Isgreater = 1;
									}else{
										if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
											result.Isgreater = 1;
										}
									}
								}else if(that.isquote == 2){
									if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["Qty"])) {
										result.Isgreater = 1;
									}else{
										if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["Qty"]))){
											result.Isgreater = 1;
										}
									}
								}
								}
								
							}
						}
						}
					// }
				}
				return result
			},
			isnulls: function(e) {
				return e == "" || typeof e == 'undefined' ? "" : e
			},
			//价格跟踪
			prices: function() {
				let data = {
					// this.NowSelectGoods
					// ClientID :this.NowSelectGoods.ClientID,
					StoreID: this.NowSelectGoods.StoreID,
					BillName: this.BillName,
					GoodsID: this.NowSelectGoods.GoodsID,
					UnitID: this.NowSelectGoods.UnitID,
					URate: this.NowSelectGoods.urate,
					VIPID: '',
					ClientID: this.ClientID
				}
				var that = this;
				Api.XH_Get_PriceFollowMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							console.log('打印价格跟踪')
							// console.log(parseFloat(that.Pricelist[0].Price))
							that.NowSelectGoods["Price"] = parseFloat(res.data.ResultMsg[0]["Price"]); //赋值第一个价格
							// console.log(res.data.ResultMsg[0]["Price"])
							for (var i in res.data.ResultMsg) {
								res.data.ResultMsg[i]["Price"] = parseFloat(res.data.ResultMsg[i]["Price"])
							}
							that.Pricelist = res.data.ResultMsg
							console.log(res.data.ResultMsg)
						}
					} else {
						Api.showTip("服务器错误!");
					}
				});
			},
			// 获取多单位
			getGoodsUnitMessage: function() {
				var that = this;
				let data = {
					GoodsID: this.NowSelectGoods.GoodsID,
				} 
				Api.Get_GoodsUnitMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							that.GoodsUnit = res.data.ResultMsg;
						}
					} else {
						Api.showTip("服务器错误!");
					}
				});
			},
			//计算折扣后商品价格
			computPrice() {
				// Amount
				// this.NowSelectGoods
				// var pr = 0;
				// console.log(this.NowSelectGoods)
				this.NowSelectGoods.Amount = parseFloat(this.NowSelectGoods.Price * this.NowSelectGoods.Qty * (this.NowSelectGoods.Discount /
					100) * (1 + this.NowSelectGoods.Tax / 100)).toFixed(2);
				// return item;
			},
			GetBatchNo: function(e) {
				console.log('输入的值')

				var val = e.detail.value
				console.log(val)
				console.log(this.storeList)
				// this.storeList
				var stutas = false;
				var index = i;
				for (var i in this.storeList) {
					if (this.storeList[i]["FBatchNo"] == val) {
						stutas = true
						index = i
						break
					}
				}
				if (stutas == true) {
					this.ProductionDate = this.timesubstr(this.storeList[index].FDate);
					this.validityDate = this.timesubstr(this.storeList[index].FValidDate);
					this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
					this.NowSelectGoods.validityDate = this.storeList[index].FValidDate;
					this.NowSelectGoods.BatchNo = this.storeList[index].FBatchNo;
					this.NowSelectGoods.stockqty = parseFloat(this.storeList[index].FQty);
				} else {
					let date = new Date();
					this.BillDate = GetApi.splitdate(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
					
					this.ProductionDate = this.BillDate;
					this.validityDate = this.DateToTime(this.BillDate,0,30);
					this.NowSelectGoods.ProductionDate = this.BillDate;
					this.NowSelectGoods.validityDate = this.DateToTime(this.BillDate,0,30);
					this.NowSelectGoods.BatchNo = val;
					this.NowSelectGoods.stockqty = 0;
				}
			},
			
			// console.log('时间')
			// console.log(date)
			
			// 1.时间,2.(0是加,1是减),3.有效天数
			DateToTime: function(e, count, num) {
				var date = new Date(e);
				var time = Date.parse(date);
				// var dates = Math.round(time / 1000) - 2592000;
				var dates = Math.round(time / 1000);
				// console.log('转换成功')
				var times = null
				if (count == 0) {
					times = (dates + (60 * 60 * 24 * (Number(num))))
				} else if (count == 1) {
					times = (dates - (60 * 60 * 24 * (Number(num))))
				}
				var datess = new Date(Math.round(times * 1000));
				var YY = datess.getFullYear() + '-';
				var MM = (datess.getMonth() + 1 < 10 ? '0' + (datess.getMonth() + 1) : datess.getMonth() + 1) + '-';
				var DD = datess.getDate() + '';
				console.log('调用了时间戳转日期')
				console.log(YY + MM + DD)
				var res = GetApi.splitdate(YY + MM + DD)
				return res
			},
		}
	}
</script>

<style>
	/* @import url("./goodlist.css"); */
	/* 弹出框样式 */
	.cu-dialog {
		height: 70%;
	}

	.new-cu-dialog {
		height: 34%;
	}

	.btn_list {
		width: 100%;
		height: 40px;
		background-color: #07C160;
		color: #fff;
		text-align: center;
		line-height: 40px;
		border-radius: 5px;
		box-shadow: 0 2px 8px rgba(211, 209, 209, 0.75);
		/* margin: 7px 0; */
		margin-top: 15px;
		font-size: 16px;
	}

	.search {
		width: 100%;
		height: 40px;
		margin: 0 10px 0 0;
		/* background-color: #00B7B8; */
		border-radius: 5px;
		border: 1px solid #bcbbbb;
		/* padding: 21px; */

	}

	.search_span {
		width: 20%;
		height: 37px;
		background-color: #659AFF;
		color: #FFFFFF;
		text-align: center;
		display: inline-block;
		line-height: 37px;
		float: right;
		border-radius: 5px;
		/* margin: 1px; */
	}

	/* .search::before{
			content: '搜索'; */

	/* border-bottom-right-radius: 5px;
			border-top-right-radius: 5px; */
	/* } */
	.search>input {
		line-height: 40px;
		float: left;
		text-align: left;
		margin-left: 5px;
		margin-top: 6px;
	}

	.content {
		font-size: 16px;
	}

	.padding-xl {
		overflow-y: scroll;
		padding: 5px 20px;
	}

	.newbtn_list {
		margin: 0;
		margin-bottom: 15px;
	}

	.cu-form-group>input {
		font-size: 12px;
	}

	.save {
		width: 100%;
		height: 40px;
		background-color: #007AFF;
		color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		text-align: center;
		font-size: 18px;
		line-height: 40px;
	}

	.setfixeds {
		width: 23%;
		margin: 4px;
	}

	.padd_left {
		padding-left: 12px;
	}

	.btn_price {
		padding: 6px 13px;
		background-color: rgb(81, 138, 188);
		color: #fff;
		border-radius: 4px;
	}

	.ls-box {
		width: 100%;
		height: 40px;
		border-radius: 5px;
		margin: 10px 0;
		line-height: 40px;
		font-size: 18px;
		text-align: center;
		color: #fff;
		background-color: #43a047;
		/* background-color: #007AFF;
		background-color: #0081FF; */
		box-shadow: 0 7px 14px 0 rgba(59, 65, 94, 0.1), 0 3px 6px 0 rgba(0, 0, 0, 0.07);
	}
</style>
